package tx.os3.clientserver.client.application;

import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import tx.os3.clientserver.client.connection.ProtocolAdapter;
import tx.os3.clientserver.client.connection.ServerConnectionProtocolAdapter;
import tx.os3.clientserver.client.gui.MainWindow;
import tx.os3.clientserver.client.handlers.UICommandHandler;
import tx.os3.clientserver.client.model.DefaultServerModel;
import tx.os3.clientserver.client.model.FileListModel;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        setupLookAndFeel();

        // Create all application components
        DefaultServerModel serverModel = new DefaultServerModel();
        FileListModel fileListModel = FileListModel.getInstance();
        ProtocolAdapter adapter = new ServerConnectionProtocolAdapter(
                serverModel, fileListModel);
        UICommandHandler handler = new UICommandHandler(adapter);
        MainWindow mainWindow = new MainWindow(handler, serverModel);

        // Connect model and view
        serverModel.addObserver(mainWindow);

        // Show window
        mainWindow.setVisible(true);
    }

    private static void setupLookAndFeel() {
        // Set look and feel
        try {
            UIManager
                    .setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        }
        catch(ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch(InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch(IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch(UnsupportedLookAndFeelException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
